package preprocess;

import java.util.*;
public class Name {
	public String last_name = null;
	public String first_name = null;
	public String first_initial = null;
	public String middle_initial = null;
	public Name(String fau,String au)
	{
		//parse FAU
		ParseFAU(fau);
		ParseAU(au);
	}
	public Name(String au)
	{
		ParseAU(au);
	}
	public void ParseFAU(String line)
	{
		line = line.replaceAll(",", " ");
		line = line.replaceAll("-"," ");
		List<String> info = new ArrayList<String>();
		StringTokenizer st = new StringTokenizer(line);
		while(st.hasMoreTokens())
		{
			String token = st.nextToken().toLowerCase();
			info.add(token);
			//System.out.println(token);
		}
		if(info.size()>=3)
		{
			last_name = info.get(0);
			first_name = info.get(1);
			middle_initial = info.get(2);
		}
		else if(info.size()==2)
		{
			last_name = info.get(0);
			first_name = info.get(1);
		}
	}
	public void ParseAU(String line)
	{
		line = line.replaceAll(",", " ");
		line = line.replaceAll("-", " ");
		List<String> info = new ArrayList<String>();
		StringTokenizer st = new StringTokenizer(line);
		while(st.hasMoreTokens())
		{
			String token = st.nextToken().toLowerCase();
			info.add(token);
			//System.out.println(token);
		}
		if(info.size()>=3)
		{
			if(last_name == null)
				last_name = info.get(0);
			first_initial = info.get(1);
			//if(middle_initial==null)
				middle_initial = info.get(2);
		}
		else if(info.size()==2)
		{
			if(last_name == null)
				last_name = info.get(0);
			first_initial = info.get(1);
			if(info.get(1).length()==2)// && middle_initial == null
			{
				first_initial = info.get(1).substring(0,1);
				middle_initial = info.get(1).substring(1,2);
			}
		}
	}
	public Name()
	{
		
	}
	public Name(String last_name, String forename, String initials){
		this.last_name = last_name;
		if(forename == null)
			return;
		String s[] = forename.split(" ");
		if(s != null && s.length==1){
			first_name = forename;
			first_initial = initials;
		}else if(s != null && s.length>=2){
			first_name = s[0];
			middle_initial = s[1];
			if(initials != null && initials.length()>1)
				first_initial = initials.substring(0,1);
			else
				first_initial = initials;
		}
	}
}
